//
//  QDFocusController.m
//  QuickDoctor
//
//  Created by ycw on 2016/12/21.
//  Copyright © 2016年 Eric. All rights reserved.
//

#import "QDFocusController.h"
#import "NetworkData.h"
#import "QDFocusCell.h"
#import "QDFocusModel.h"
#import "QDDoctorMassegeController.h"

static NSString *cellID = @"focusCell";

@interface QDFocusController ()<UITableViewDelegate,UITableViewDataSource>

@property(strong,nonatomic) NSArray<QDFocusModel *> *modelList;

@property(weak,nonatomic) UITableView *tableView;

@end

@implementation QDFocusController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.title = @"关注医生";
    
    [self setUpUI];
    
    [self getData];
    
}

#pragma mark
#pragma mark - 搭建界面
- (void) setUpUI
{
    
    UITableView *tableView = [[UITableView alloc] initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain];
    
    [self.view addSubview:tableView];
    
    self.tableView = tableView;
    
    tableView.delegate = self;
    
    tableView.dataSource = self;
    
    tableView.estimatedRowHeight = 200;
    
    tableView.rowHeight = UITableViewAutomaticDimension;
    
    //去掉分割线
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    [tableView registerClass:[QDFocusCell class] forCellReuseIdentifier:cellID];
    
}

#pragma mark
#pragma mark - 加载数据
- (void) getData
{
    
    [[QDFocusModel new] addDoctorListWithCompleteBlock:^(NSArray<QDFocusModel *> *modelList) {
        
        self.modelList = modelList;
        
        
    }];
    
}

#pragma mark
#pragma mark - 刷新数据
- (void)setModelList:(NSArray<QDFocusModel *> *)modelList
{
    
    _modelList = modelList;
    
    [self.tableView reloadData];
    
}


#pragma mark
#pragma mark - 实现数据源代理方法
 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    
    return 1;
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    return self.modelList.count;
    
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    QDFocusCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];
    
    QDFocusModel *model = self.modelList[indexPath.row];
    
    cell.modelList = model;
    
    return cell;
    
}
//取消选中
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    QDDoctorMassegeController *doctorC = [[QDDoctorMassegeController alloc] init];
    doctorC.model = self.modelList[indexPath.row];
    
    [self.navigationController pushViewController:doctorC animated:YES];
    
  
}


@end
